package dao.impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.handlers.BeanHandler;

import bean.Blacklist;
import dao.BlacklistDao;


//Apply
public class BlacklistDaoImpl extends BaseDao implements BlacklistDao{

	@Override
	public Integer selectBlacklistbyid(Integer id) {
		try {
			Object query2=query.query("select * from blacklist where blacklistid=?",id,new BeanHandler<Blacklist>(Blacklist.class));
			return Integer.parseInt(query2.toString());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer deleteBlacklistbyid(Integer id) {
		try {
			return query.update("delete from blacklist where blacklistid=?",id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer updateBlacklist(Blacklist info) {
		String sql="update blacklist set userid=?,beblackuserid=? where blacklistid=?";
		try {
			return query.update(sql,info.getUserid(),info.getBeblackuserid());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer addBlacklist(Blacklist info) {
		String sql="insert into blacklist(userid,beblackuserid) VALUES(?,?)";
		try {
			return query.update(sql,info.getUserid(),info.getBeblackuserid());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

}
